#include<iostream>
#include<vector>
#include<string>

using namespace std;


string isIpv4(string IP) {
    vector<string> theIp;
    string cur;
    bool flag = true;
    for (auto ip : IP) {
        if (ip != '.') {
            //如果不是数字就直接返回错
            if (!isdigit(ip)) return "Neither";
            cur += ip;
        }
        else {
            //如果取到.就说明已经取到其中一段数字
            //将其放入vector，并清空cur
            theIp.push_back(cur);
            cur.clear();
        }
    }
    if(!cur.empty()) theIp.push_back(cur);
    for (auto ip : theIp) {
        //判断前导零
        if ((ip.size() > 1) && (ip[0] == '0')) flag = false;
        int var = stoi(ip);
        if (var > 255) flag = false;
    }
    if (flag && theIp.size() == 4) return "IPv4";
    else return "Neither";
}
string isIpv6(string IP) {
    vector<string> theIp;
    string cur;
    bool flag = true;
    for (auto ip : IP) {
        if (ip != ':') {
            //判断是否是题目要求的数字
            if (!(isdigit(ip)
                || (ip >= 'a' && ip <= 'z')
                || (ip >= 'A' && ip <= 'Z'))) return "Neither";
            cur += ip;
        }
        else {
            //如果取到.就说明已经取到其中一段字符
            //将其放入vector，并清空cur
            //count存放字符的段数
            theIp.push_back(cur);
            cur.clear();
        }
    }
    if (!cur.empty()) theIp.push_back(cur);
    for (auto ip : theIp)
    {
        if (ip.size() > 4) flag = false;
    }
    if (flag && theIp.size() == 8) return "IPv6";
    else return "Neither";
}
string solve(string IP) {
    for (auto str : IP) {
        if (str == '.') return isIpv4(IP);
        if (str == ':') return isIpv6(IP);
    }
    return "Neither";
}

int main()
{
    string IP = "2001:0db8:85a3:0:0:8A2E:0370:7334";
    solve(IP);
	return 0;
}